package com.ddyx.util;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @ClassName: CalculateUtil.java
 * @Description: 时间计算工具
 * @author: liuhoujie
 * @date: 2018年3月23日
 */
public class CalculateUtil {
	
	public static SimpleDateFormat format_ymd_hms = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	public static SimpleDateFormat format_ymd = new SimpleDateFormat("yyyy-MM-dd");
	

	/**
	 * 时间向后推移12小时 隔天
	 */
	public static Date dateAddOne(Date date) {
		Calendar Cal = Calendar.getInstance();

		Cal.setTime(date);

		Cal.add(Calendar.HOUR_OF_DAY, 12);

		date = Cal.getTime();
		// System.out.println("date:"+Cal.getTime());
		return date;
	}
	
	/**
	 * 时间推移指定天
	 */
	public static Date dayChange(Date date,Integer day) {
		Calendar Cal = Calendar.getInstance();

		Cal.setTime(date);

		Cal.add(Calendar.DAY_OF_WEEK, day);

		date = Cal.getTime();
		// System.out.println("date:"+Cal.getTime());
		return date;
	}
	
	
	public static void main(String[] args) {
		List currentPeriod = new ArrayList<>();
		List priorPeriod = new ArrayList<>();
		for (int i = 0; i < 7; i++) {
//			Date day = CalculateUtil.dayChange(new Date(),-i);
//			System.out.println(format_ymd.format(day));
			System.out.println(format_ymd.format(CalculateUtil.dayChange(new Date(),-i)));
			System.out.println(format_ymd.format(CalculateUtil.dayChange(new Date(),-(i+7))));
		}
//		System.out.println("=================================================");
//		/*上期priorPeriod*/
//		for (int i = 7; i < 14; i++) {
//			Date day = CalculateUtil.dayChange(new Date(),-i);
//			System.out.println(format_ymd.format(day));
//		}
		
	}
	
	
	
	
	/**
	 * 浏览预约转换计算方法(弃用)
	 * @param storeBookingTotal
	 * @param storePvCount
	 * @return
	 */
	public static String getGoodsPv2bkRate(int storeBookingTotal, int storePvCount) {
		if(storeBookingTotal!=0&&storePvCount!=0) {
			DecimalFormat df = new DecimalFormat("0.00");//格式化小数
			String goodsPv2bkRate = df.format((float)storeBookingTotal*100/storePvCount);//返回的是String类型    
			return goodsPv2bkRate;
		}
		return "0";
		
	}
}
